package two;

import java.util.Scanner;

public class test17965 {
    public static int[] array;
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int m = scanner.nextInt();
        array = new int[n+1];
        System.out.println(f1(n) + " " + f2(n, m));
    }

    private static int f2(int n, int m) {
        if (n == 1) {
            return 1;
        } else if(n>1){
            int Num=1;
           for (int i=0;i<n-1;i++){
               Num =(Num+m-1)%(i+2)+1;
           }
           return Num;
        }
        return 0;
    }

    private static int f1(int n) {
        int s = (int) (Math.log(n) / Math.log(2));
        return (int) Math.pow(2, s);
    }
}
